home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 2 / Amiga Tools 2.iso / grafik / bildanzeiger / seepix / source.lha / FadeTo.c < prev    next >
Text File  |  1992-11-27  |  6KB  |  176 lines

  1. /**FadeTo.c**************************************************************
  2.  *                                    *
  3.  *   SeePix -- by Hank Schafer                        *
  4.  *                                    *
  5.  *   SeePix is an IFF Picture Viewer.  It works with Lo-Res,        *
  6.  *   Med-Res, Hi-Res, HAM, and EHB formats.  I'm working on support     *
  7.  *   for X-Specs, and Anim5 formats.                    *
  8.  *                                    *
  9.  *   SeePix is based on a program by Olaf Barthel, called        *
  10.  *   'LoadImage'.  As released, LoadImage had a couple of bugs.     *
  11.  *   The Amiga-Key alternatives to menu use didn't all work.  That's    *
  12.  *   been fixed.  There were two separate print functions in LoadImage    *
  13.  *   which behaved exactly the same.  The redundancy was eliminated.    *
  14.  *   LoadImage used the Topaz ROMFONT, and made no allowances for a    *
  15.  *   different system default font (under 2.04).  I added a built-in    *
  16.  *   font.  I've reworked the code considerably from the original       *
  17.  *   release, to allow for optimizations based on time and space.    *
  18.  *                                    *
  19.  *   SeePix features a palette tool which allows "tweaking" of colors    *
  20.  *   prior to printing, allowing you to modify the color printout to    *
  21.  *   more closely resemble the original graphics (Blue is Blue, not    *
  22.  *   Purple).  SeePix can be Iconified.  SeePix features an ARP     *
  23.  *   interface.  SeePix now uses the PathMaster File Selector.        *
  24.  *                                    *
  25.  ************************************************************************
  26.  *                                                                      *
  27.  *   SeePix Copyright © 1992 by Hank Schafer; all rights reserved.      *
  28.  *                                                                      *
  29.  *   This program is free software; you can redistribute it and/or      *
  30.  *   modify it under the terms of the GNU General Public License as     *
  31.  *   published by the Free Software Foundation, either version 1, or    *
  32.  *   (at your option) any later version.                                *
  33.  *                                                                      *
  34.  *   This program is distributed in the hope that it will be useful,    *
  35.  *   but WITHOUT ANY WARRANTY; without even the implied warranty of     *
  36.  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU  *
  37.  *   General Public License for more details.                           *
  38.  *                                                                      *
  39.  *   You should have received a copy of the GNU General Public License  *
  40.  *   along with this program; if not, write to:                         *
  41.  *                 Free Software Foundation, Inc.                       *
  42.  *                 675 Massachusetts Ave.                               *
  43.  *                 Cambridge  MA  02139, USA                            *
  44.  *                                                                      *
  45.  **************** Special Function Copyright Notices ********************
  46.  *                                    *
  47.  ****LoadImage Copyright Notice:                    *
  48.  *                                    *
  49.  *   LoadImage is © Copyright 1988, 1989, 1990 by MXM, all rights    *
  50.  *   reserved, written by Olaf Barthel.  No guarantees of any kind are    *
  51.  *   made that this program is 100% reliable.  Use this program on    *
  52.  *   your own risk!                            *
  53.  *                                    *
  54.  ****Iconify Copyright Notice:                        *
  55.  *                                    *
  56.  *   Copyright 1987 by Leo L. Schwab.                    *
  57.  *   Permission is hereby granted for use in any and all programs,    *
  58.  *   both Public Domain and commercial in nature, provided this     *
  59.  *   Copyright notice is left intact.                    *
  60.  *                                    *
  61.  ****ColorWindow (Palette) Copyright Notice:                *
  62.  *                                    *
  63.  * ColorWindow Routine    --  Color Window Routines            *
  64.  *     from Book 1 of the Amiga Programmers' Suite by RJ Mical          *
  65.  *                                    *
  66.  * Copyright (C) 1986, 1987, Robert J. Mical                *
  67.  * All Rights Reserved.                         *
  68.  *                                    *
  69.  ****PathMaster Copyright Notice:                    *
  70.  *                                    *
  71.  * -------------------------------------------------------------------- *
  72.  *   Copyright © 1989 Justin V. McCormick.  All Rights Reserved.    *
  73.  * -------------------------------------------------------------------- *
  74.  *                                    *
  75.  *    The PathMaster name is a trademark of Justin V. McCormick.    *
  76.  *                                    *
  77.  *   PathMaster File Selector source and documentation written by:    *
  78.  *                                    *
  79.  *             Justin V. McCormick.                *
  80.  *           Copyright © 1989 by Justin V. McCormick.         *
  81.  *             All Rights Reserved.                *
  82.  *                                    *
  83.  * -------------------------------------------------------------------- *
  84.  ************************************************************************
  85.  *                                    *
  86.  *   Hope this is something you can use and enjoy.            *
  87.  *                                    *
  88.  ************************************************************************/
  89.  
  90. /*
  91.  * FadeTo():
  92.  *
  93.  * Fades a palette into a different palette or color.
  94.  */
  95.  
  96. VOID
  97. FadeTo(struct ViewPort * VPort, UWORD * From, UWORD * To, LONG NumColors, LONG ToCol, LONG FromCol)
  98. {
  99.     UWORD        FromTemp[32];
  100.     UWORD        ToTemp[32];
  101.  
  102.     WORD        i, j, R1, G1, B1, R2, G2, B2;
  103.  
  104.     /* A bit too large? */
  105.  
  106.     if (NumColors > 32)
  107.     NumColors = 32;
  108.  
  109.     /* Do we have a source palette? */
  110.  
  111.     if (From)
  112.     CopyMem(&From[0], &FromTemp[0], sizeof(UWORD) * 32);
  113.     else
  114.     memset(&FromTemp[0], FromCol, sizeof(UWORD) * 32);
  115.  
  116.     /* Do we have a destination palette? */
  117.  
  118.     if (To)
  119.     CopyMem(&To[0], &ToTemp[0], sizeof(UWORD) * 32);
  120.     else
  121.     memset(&ToTemp[0], ToCol, sizeof(UWORD) * 32);
  122.  
  123.     /* Let's get into action. */
  124.  
  125.     for (j = 0; j < 16; j++) {
  126.     for (i = 0; i < NumColors; i++) {
  127.  
  128.         /* Split the source color. */
  129.  
  130.         R1 = (FromTemp[i] >> 8) & 0xF;
  131.         G1 = (FromTemp[i] >> 4) & 0xF;
  132.         B1 = (FromTemp[i]) & 0xF;
  133.  
  134.         /* Split the destination color. */
  135.  
  136.         R2 = (ToTemp[i] >> 8) & 0xF;
  137.         G2 = (ToTemp[i] >> 4) & 0xF;
  138.         B2 = (ToTemp[i]) & 0xF;
  139.  
  140.         /* Adjust the colors. */
  141.  
  142.         if (R1 > R2)
  143.         R1--;
  144.  
  145.         if (G1 > G2)
  146.         G1--;
  147.  
  148.         if (B1 > B2)
  149.         B1--;
  150.  
  151.         /* Adjust the colors. */
  152.  
  153.         if (R1 < R2)
  154.         R1++;
  155.  
  156.         if (G1 < G2)
  157.         G1++;
  158.  
  159.         if (B1 < B2)
  160.         B1++;
  161.  
  162.         /* Put it together again. */
  163.  
  164.         FromTemp[i] = (R1 << 8) | (G1 << 4) | B1;
  165.     }
  166.  
  167.     /* Wait a bit. */
  168.  
  169.     Delay(2);
  170.  
  171.     /* Load the new map. */
  172.  
  173.     LoadRGB4(VPort, FromTemp, NumColors);
  174.     }
  175. }
  176.